<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\usersBillsSums;


Class UsersBillsSumsModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
    
    public function findAll()
    {
        //$sums = $this->em->getRepository('BillingBundle:usersBillsSums')->findAll();
        //return $sums;
        $query = $this->em->createQuery('SELECT s FROM BillingBundle:usersBillsSums s order by s.summ');
        $sums = $query->getResult();
        return $sums;
    }

    public function findAllActive()
    {
        $query = $this->em->createQuery('SELECT s FROM BillingBundle:usersBillsSums s where s.is_active=1 order by s.summ');
        $sums = $query->getResult();
        return $sums;
        //$sums = $this->em->getRepository('BillingBundle:usersBillsSums')->findBy(array('is_active' => '1'));
        //return $sums;
    }
    
    public function findByPK($id)
    {
        $summ = $this->em->find('BillingBundle:usersBillsSums', $id);
        return $summ;
    }
    
    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }
    
    public function removeByPK($sum_id)
    {
        $summ = $this->em->find('BillingBundle:usersBillsSums', $sum_id);
        $this->em->remove($summ);
        $this->em->flush();
    }
}
?>
